$(function(){
//倒计时
window.setInterval(changeRemainTime, 1000);
//整除
function div(exp1, exp2)  
{  
    var n1 = Math.round(exp1); //四舍五入  
    var n2 = Math.round(exp2); //四舍五入  
    var rslt = n1/n2; //除  
    if (rslt >= 0)  
    {  
        rslt = Math.floor(rslt); //返回小于等于原rslt的最大整数。  
    }  
    else  
    {  
        rslt = Math.ceil(rslt); //返回大于等于原rslt的最小整数。  
    }
    return rslt;  
    }

function changeRemainTime(){
    $('.pro-timer').each(function(){
        var me = $(this);
        var seconds = me.find('.remain-seconds').text();
        var day = 60*60*24;
        var hour = 60*60;
        var minute = 60;
        var remainD = 0;
        var remainH = 0;
        var remainM = 0;
        var remainS = 0;
        if(seconds>0){
            remainD = div(seconds,day);
            remainH = div((seconds%day),hour);
            remainM = div((seconds%hour),minute);;
            remainS = seconds%minute;
        }
        if(me.find('.d').length>0)//判断天是否存在
        {
            me.find('.d').text(remainD<10?'0'+remainD:remainD);
        }
        else
        {
            remainH = remainH + remainD*24;
        }
        me.find('.h').text(remainH<10?'0'+remainH:remainH);
        me.find('.m').text(remainM<10?'0'+remainM:remainM);
        me.find('.s').text(remainS<10?'0'+remainS:remainS);
        
        seconds--;
        me.find('.remain-seconds').text(seconds);
    });
    }
});

